<html><body><pre><script>

Function.prototype.method = function (name, func) {
    if (!this.prototype[name]) {
        this.prototype[name] = func;
        return this;
    }
};

Array.method('reduce', function (f, value) {
    var i;
    for (i = 0; i < this.length; i += 1) {
        value = f(this[i], value);
    }
    return value;
});

var data = [4, 8, 15, 16, 23, 42];
var add = function (a, b) {
    return a + b;
};

document.write(data, '\n');
document.write(data.reduce(add, 0), '\n');
document.write(data.reduce(function(a,b){return a*b}, 1), '\n');

</script></pre></body></html>



